package cn.wit.db.web;

import cn.wit.db.entity.AjaxResult;
import cn.wit.db.entity.Reward;
import cn.wit.db.mapper.RewardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RewardController {
    @Autowired
    RewardMapper mapper;

    //查询
    @GetMapping("/reward")
    public List<Reward> getRewardAndPunishment(){
        return mapper.selectAll();
    }
    //插入
    @PostMapping("/reward")
    public AjaxResult createReward(@RequestBody Reward reward){
         mapper.insert(reward);
         return AjaxResult.success();
    }

    //删除
    @DeleteMapping("/reward")
    public AjaxResult deleteReward(@PathVariable Reward reward){
        mapper.deleteByPrimaryKey(reward.getId());
        return AjaxResult.success();
    }

    //修改
    @PutMapping("/reward")
    public AjaxResult updateReward(@PathVariable Reward reward){
         mapper.updateByPrimaryKey(reward);
         return AjaxResult.success();
    }
}
